<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>子传父</title>
</head>

<body>
    <div id="app">
        <parent></parent>
    </div>
    <template id="child">
        <div>
            <button @click="sendmsg">发送信息给父组件</button>
            <input type="text" v-model="msg">
        </div>
    </template>
</body>
<script src="https://static.iamflame.top/cdn/javascript/vue@2.js"></script>
<script>
    // 子组件
    Vue.component('child', {
        template: '#child',
        data() {
            return {
                msg: "子组件信息"
            }
        },
        methods: {
            sendmsg() {
                this.$emit('childSend', this.msg)
            }
        }
    })


    // 父组件
    Vue.component('parent', {
        template: '<div><child @childSend="getmsg"></child> <p>子组件传来的值：{{message}}</p></div>',
        data() {
            return {
                message: ""
            }
        },
        methods: {
            getmsg(e) {
                this.message = e
            }
        }
    })

    let vm = new Vue({
        el: "#app"
    })

</script>

</html>